package com.hfzy.ihk.web.callhistoryold.jobs.demo;

import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.dataflow.DataflowJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@Component("flowDemoJob")
public class FlowDemoJob implements DataflowJob<Integer> {

    private int i = 0;
    @Autowired
    StringRedisTemplate stringRedisTemplate;



    @Override
    public List<Integer> fetchData(ShardingContext shardingContext) {
        try {
            log.info("开始抓取数据:CallHistoryOldJob,初始id:" + i);
            List<Integer> datas = new ArrayList<Integer>();
            datas.add(i + 1);
            Thread.sleep(5000L);

            datas.add(i + 2);
            Thread.sleep(5000L);

            i += 2;
            for(int i=0;i<datas.size();i++){
                System.out.println("抓到:" + datas.get(i));
            }
            return datas;
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }

    }

    @Override
    public void processData(ShardingContext shardingContext, List<Integer> list) {
        if(list != null){
            for(int i=0;i<list.size();i++){
                System.out.println("===>" + list.get(i));
            }
        }
    }
}
